package com.shaomengjie.smjmvp.retrofit.utils;

import com.shaomengjie.smjmvp.MyApplication;
import com.shaomengjie.smjmvp.R;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by shaomengjie on 2017/4/7.
 * pdsshaomengjie@live.com
 */

public class RetrofitUtils {
    private static Retrofit mRetrofit;
    private static OkHttpClient mOkHttpClient;
    private static Retrofit mRetrofitforwx;

    /**
     * 获取Retrofit对象
     *
     * @return
     */
    protected static Retrofit getRetrofit() {

        if (null == mRetrofit) {

            if (null == mOkHttpClient) {
                mOkHttpClient = OkHttpUtils.getOkHttpClient();
            }

            mRetrofit = new Retrofit.Builder()
                    .baseUrl(MyApplication.getContext().getString(R.string.baseUrl))
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .client(mOkHttpClient)
                    .build();

        }

        return mRetrofit;
    }

    protected static Retrofit getRetrofitforwx() {

        if (null == mRetrofitforwx) {

            if (null == mOkHttpClient) {
                mOkHttpClient = OkHttpUtils.getOkHttpClient();
            }

            mRetrofitforwx = new Retrofit.Builder()
                    .baseUrl("https://api.weixin.qq.com/")
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                    .client(mOkHttpClient)
                    .build();

        }

        return mRetrofitforwx;
    }
}
